package org.project.d.starter.network;

import org.project.d.network.exception.BusinessProcessingExceptionHandlerManager;
import org.springframework.boot.context.event.ApplicationReadyEvent;
import org.springframework.context.ApplicationListener;

import java.util.Map;

/**
 * @author lin
 * @version V1.0
 * @description
 * @date 2020/10/8 4:29 下午
 */
public class BusinessProcessingExceptionRegistrar implements ApplicationListener<ApplicationReadyEvent> {
    @Override
    public void onApplicationEvent(ApplicationReadyEvent event) {
        Map<String, RegistrarBusinessProcessingException> beansOfType = event.getApplicationContext().getBeansOfType(RegistrarBusinessProcessingException.class);
        beansOfType.forEach((k,v)-> BusinessProcessingExceptionHandlerManager.addBusinessProcessingExceptionHandler(v.getCmd(),v.getBusinessProcessingExceptionHandler()));
    }
}
